package com.dream.xcarrecorder;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;
import android.widget.VideoView;

import androidx.annotation.Nullable;

import org.w3c.dom.Text;

import java.io.File;

public class VideoActivity extends Activity {

    private final static String KEY_PATH = "KEY_PATH";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);

        VideoView v = (VideoView)findViewById(R.id.videoView);
        Intent intent = getIntent();
        String path = intent.getStringExtra(KEY_PATH);

        TextView tv = findViewById(R.id.tv_video_size);

        File f = new File(path);
        if (f.exists()){
            tv.setText(f.length()/1024 + "KB");
        }

        if (!TextUtils.isEmpty(path)){
            v.setVideoPath(path);
            v.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    //视频加载完成,可以开始播放视频
                    v.start();
                }
            });
        }
    }

    public static void startActivity(Context ct,String path){
        Intent i = new Intent(ct, VideoActivity.class);
        i.putExtra(KEY_PATH,path);
        ct.startActivity(i);
    }
}
